extends NodeState


@export var enemy: BasicEnemy


var waitting_time: float

const WAITTING_TIME_THRESHOLD := 0.001


func _on_process(delta : float) -> void:
	process_animation()
	if waitting_time > WAITTING_TIME_THRESHOLD:
		waitting_time -= delta



func _on_next_transitions() -> void:
	if not enemy.player.enabled:
		return
	# 达到等待时间
	if waitting_time < WAITTING_TIME_THRESHOLD:
		if enemy.is_flying_knife_attack() or enemy.is_shoot_gun_attack():
			transition_state(BasicEnemy.STATE_WALK)
		elif enemy.is_player_within_attack_range():
			transition_state(BasicEnemy.STATE_PUNCH)
		else:
			transition_state(BasicEnemy.STATE_WALK)


func _on_enter() -> void:
	enemy.damageReceiver.set_deferred("monitorable", true)
	random_wait()


func process_animation():
	enemy.animationPlayer.play(BasicEnemy.ANIMATION_IDLE)


func random_wait():
	waitting_time = randf_range(enemy.idle_random_range.x, enemy.idle_random_range.y)
